#!/bin/bash

# 检查在分页方法中错误使用 selectList 的问题

echo "检查在分页方法中错误使用 selectList 的问题..."
echo "=========================================="

# 查找所有包含分页相关的 Java 文件
files=$(find fuint-application/src/main/java -name "*ServiceImpl.java" -exec grep -l "PaginationRequest\|PaginationResponse" {} \;)

problem_files=()

for file in $files; do
    # 检查是否在分页方法中使用了 selectList
    if grep -A 30 -B 5 "PaginationRequest.*paginationRequest" "$file" | grep -q "selectList.*lambdaQueryWrapper"; then
        echo "❌ 发现问题文件: $file"
        echo "   在分页方法中使用了 selectList 而不是 selectPage"
        
        # 显示具体的问题代码段
        echo "   问题代码段："
        grep -A 30 -B 5 "PaginationRequest.*paginationRequest" "$file" | grep -A 10 -B 5 "selectList.*lambdaQueryWrapper" | head -20
        echo "   ----------------------------------------"
        echo ""
        
        problem_files+=("$file")
    fi
done

echo ""
echo "检查结果汇总："
echo "=========================================="
if [ ${#problem_files[@]} -eq 0 ]; then
    echo "✅ 没有发现问题文件"
else
    echo "❌ 发现 ${#problem_files[@]} 个问题文件："
    for file in "${problem_files[@]}"; do
        echo "   - $file"
    done
fi

echo ""
echo "修复建议："
echo "=========================================="
echo "将分页方法中的："
echo "  List<Entity> dataList = mapper.selectList(lambdaQueryWrapper);"
echo "替换为："
echo "  Page<Entity> page = new Page<>(currentPage, pageSize);"
echo "  Page<Entity> pageResult = mapper.selectPage(page, lambdaQueryWrapper);"
echo "  List<Entity> dataList = pageResult.getRecords();"
